Step 10: DELETE Request

Let's include a route to delete a bookmark.

HTTP MethodDELETE
API Endpoint/bookmarks/:id
Request Path Parameterid
Request Query Parameter
Request Body
Response BodyJSON object (bookmark)
Response Status200

Notice the path (endpoint) is similar to the GET request we had earlier for retrieving a bookmark given its ID. By convention, we return the deleted bookmark (with status code 200).

Update src/routes/bookmarks.js to include the following route:

router.delete("/bookmarks/:id", (req, res) => {
  const { id } = req.params;
  const bookmark = bookmarkDao.delete(id);
  res.json({
    status: 200,
    message: `Successfully deleted the following bookmark!`,
    data: bookmark,
  });
});

Save the code and commit the changes. Then, test this endpoint in Postman.

Untitled